package cj.web.admin.dao;
/*
 *  
 *  
*/
import java.util.List;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;
import cj.web.admin.domain.Comments;

/**
 * 
 * @author 
 *
 */
@DAO
public interface CommentsDAO{
	
	@SQL("SELECT * FROM Comments WHERE deleteFlag=1 #if(:t.reply!=''){and reply like '%##(:t.reply)%' } ORDER BY releaseState ,createAt DESC LIMIT :t.start,:t.length ")
    List<Comments> queryByComments(@SQLParam("t") Comments comments);
	
	@SQL("SELECT count(*) FROM Comments WHERE deleteFlag=1 #if(:t.reply!=''){and reply like '%##(:t.reply)%' } ")
    int queryByCommentsSize(@SQLParam("t") Comments comments);
	
	@SQL("SELECT * FROM Comments WHERE deleteFlag=1 #if(:t.contents!=''){and contents like '%##(:t.contents)%' } #if(:t.userId!=''){ and replyUserId =:t.userId } ORDER BY updateAt DESC,createAt DESC LIMIT :t.start,:t.length ")
    List<Comments> query(@SQLParam("t") Comments comments);
	
	@SQL("SELECT count(*) FROM Comments WHERE deleteFlag=1 #if(:t.contents!=''){and contents like '%##(:t.contents)%' } #if(:t.userId!=''){ and replyUserId =:t.userId }")
    int querySize(@SQLParam("t") Comments comments);
    
	@SQL("SELECT * FROM Comments WHERE id=:1 ")
    Comments queryById(int id);
    
	@SQL("UPDATE Comments SET reply=:t.reply,isAnonymous=:t.isAnonymous,editReply=:t.editReply,editReplyUserId=:t.editReplyUserId,releaseState=:t.releaseState,updateUser=:t.updateUser,updateAt=now() WHERE id=:t.id")
    void update(@SQLParam("t") Comments comments);
    
    @SQL("UPDATE Comments SET deleteFlag=0 WHERE id=:1")
    void deleteById(int id);
    
    @SQL("UPDATE Comments SET stickAT=now(),updateAT=now() WHERE id=:1")
    void updateByStickTime(int id);
    
    @SQL("UPDATE Comments SET releaseState=0,updateAT=now() WHERE id=:1")
    void updateByChannelRelease(int id);
	
	@SQL("UPDATE Comments SET stickAT=null,updateAT=now() WHERE id=:1")
    void updateByStickTimeIsNull(int id);
	
	//修改新闻评论数
	@SQL("update News set commentsNum=commentsNum+1 where id=:1")
    void addCommentsById(int id);
	
	//修改新闻评论数
	@SQL("update News set commentsNum=commentsNum-1 where id=:1")
    void subCommentsById(int id);
	
	@SQL("INSERT INTO Comments (userId,userName,newsId,newsTitle,contents,isAnonymous,releaseState,reply,replyUserId,replyName,editReplyUserId,editReply,praiseNum,deleteFlag,createUser,createAt,updateUser,updateAt) VALUES (:t.userId,:t.userName,:t.newsId,:t.newsTitle,:t.contents,:t.isAnonymous,:t.releaseState,:t.reply,:t.replyUserId,:t.replyName,:t.editReplyUserId,:t.editReply,0,1,:t.createUser,now(),:t.updateUser,now()) ")
    int create(@SQLParam("t") Comments comments);
}